package ${controllerPackage};

import javax.servlet.http.HttpServletRequest;

import com.spa.common.api.vo.Result;
import com.spa.common.aspect.annotation.AutoLog;
import ${entityPackage}.${entity};

import ${servicePackage}.${entity}Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 描述: ${table.comment}
 * author: ${author}
 * date: ${date}
 */
@Api(tags="${table.comment}")
@RestController
@RequestMapping(value="/${packages}/${entity?uncap_first}")
public class ${entity}Controller {

    @Autowired
	private ${entity}Service ${entity?uncap_first}Service;
	
	/**
	 * 分页列表查询
	 * 
	 * @param ${entity?uncap_first}
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@AutoLog(value = "${table.comment}-列表")
	@GetMapping(value = "/listByPage")
	public Result<?> queryPageList(HttpServletRequest req, @RequestParam(name = "page", defaultValue = "1") Integer page,
			@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
		return ${entity?uncap_first}Service.queryPageList(req, page, pageSize);
	}
     
    /**
	 * 添加
	 *
	 * @param ${entity?uncap_first}
	 * @return
	 */
	@AutoLog(value = "${table.comment}-添加")
	@ApiOperation(value="${table.comment}-添加", notes="${table.comment}-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody ${entity} ${entity?uncap_first}) {
		return ${entity?uncap_first}Service.insert(${entity?uncap_first});
	}
	
	/**
	 * 编辑
	 *
	 * @param ${entity?uncap_first}
	 * @return
	 */
	@AutoLog(value = "${table.comment}-编辑")
	@ApiOperation(value="${table.comment}-编辑", notes="${table.comment}-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody ${entity} ${entity?uncap_first}) {
		return ${entity?uncap_first}Service.saveById(${entity?uncap_first});
	}
	
	/**
	 * 通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "${table.comment}-通过id删除")
	@ApiOperation(value="${table.comment}-通过id删除", notes="${table.comment}-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) int id) {
		return ${entity?uncap_first}Service.deleteById(id);
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "${table.comment}-通过id查询")
	@ApiOperation(value="${table.comment}-通过id查询", notes="${table.comment}-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) int id) {
		return ${entity?uncap_first}Service.selectById(id);
	}
}
